package com.sl.ffmpeg_plugin

import android.graphics.Bitmap
import android.util.Log
import io.reactivex.*
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import java.io.File
import java.io.FileOutputStream

object FileManager {
    fun saveImage2Local(imgList: List<Bitmap>, fileDirPath: String) {
        var sub = Observable.fromIterable(imgList).map {
            var path = "";
            var file = File(fileDirPath, "/${System.currentTimeMillis()}.png")
            file.createNewFile();
            var outPut: FileOutputStream = FileOutputStream(file)
            it.compress(Bitmap.CompressFormat.PNG,100,outPut)
            outPut.flush()
            outPut.close()
            "$fileDirPath${System.currentTimeMillis()}.png"
        }.toList().subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(object : SingleObserver<List<String>> {
            override fun onSuccess(t: List<String>) {

            }

            override fun onSubscribe(d: Disposable) {
            }

            override fun onError(e: Throwable) {
                Log.e("看看数据", e.toString())
            }
        })
    }


    interface SaveImgListener {
        fun saveComplete(dataList: List<String>)
    }
}